<%--
  Created by IntelliJ IDEA.
  User: sxing
  Date: 14-10-4
  Time: 上午10:40
--%>


<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <meta name="layout" content="manage"/>
    <title>系统管理</title>
</head>

<body>
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            基础设置
        </li>
        <li class="active"><g:link controller="mngCategory">分类管理</g:link></li>
    </ul><!-- .breadcrumb -->
    <div class="nav-search" id="nav-search">

    </div><!-- #nav-search -->
</div>
<div class="page-content">
    <div class="page-header">
        <h1>
            分类管理
            <small>
                <i class="icon-double-angle-right"></i>
                维护分类信息
            </small>
        </h1>
    </div><!-- /.page-header -->
    <div class="row">
        <div class="col-xs-12">
            <g:if test="${flash.message}">
                <div class="message alert alert-info">
                    <g:message message="${flash.message}"/>
                </div>
            </g:if>
        <!-- PAGE CONTENT BEGINS -->
            <table id="grid"></table>
            <div id="gridPager"/>
            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</div>
<r:script>
        var gridSelector = "#grid";
        var gridPagerSelector = "#gridPager";
        var listUrl = "<g:createLink controller="mngCategory" action="list" params="[format: 'json']"/>";
        jQuery(function($) {
            $(gridSelector).jqGrid({
                caption: "图片分类表",
                url:  listUrl,
                 datatype: 'json',
                 colNames: [  "编码", "分类名称","备注","类型"],
                 colModel: [
                    {name: 'id', index: 'id', width: 80,search: false},
                    { name: 'name', index: 'name', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    {name: 'remark', index: 'remark', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    {name: 'categoryType', index: 'categoryType', width: 120,editoptions:{value:'1:主题;2:风格;'},
                         formatter:function(v){
                                    if(v==1){
                                         return"主题";
                                    }else if(v==2){
                                         return"风格";
                                    }
                                }
                     }
                ],
                ondblClickRow: function(id) {
                    if (id) {
                        window.location.href="<g:createLink action='edit'/>?id=" + id;
                    }
                },
                viewrecords: true,
                pager: gridPagerSelector,
                autowidth: true,
                height: 'auto',
                rowNum: 25,
                recordtext: "从{0}到{1}共{2}",
                multiselect: true,
			    multiboxonly: true,
                jsonReader: {
                    root: 'datas',
                    page: 'page',
                    repeatitems : false
                }
            });
            $(gridSelector).jqGrid('filterToolbar',{
                autosearch: true,
                searchOnEnter: true,
                searchOperators: true,
                stringResult:true
            });
            $(gridSelector).jqGrid('navGrid',gridPagerSelector,
                { 	//navbar options
                    add: true,
                    addicon : 'icon-plus-sign purple',
                    addfunc: function() {
                        window.location.href="<g:createLink action='create'/>";
                    },
                    edit: true,
                    del: true,
                    refreshicon : 'icon-refresh green'
                },
                { //edit
                    recreateForm: true,
                    beforeInitData: function(form) {
                        var id = $(this).jqGrid('getGridParam','selrow');
                        window.location.href="<g:createLink action='edit'/>?id=" + id;
                        return false;
                    }
                },
                { //add
                },
                {   //delete
                    url: '<g:createLink action="delete" params="[format: 'json']"/>',
                    recreateForm: true,
                    beforeShowForm: function(form, oper) {
                        form.jqFormToken({
                            tokenUrl: '<g:createLink action="resetToken"/>'
                        });
                    },
                    afterSubmit: function(response, posted) {
                        var rs = $.parseJSON(response.responseText);
                        var results = [ rs["code"] == 0, rs["message"]];
                        if (results) {
                            $(gridSelector).setGridParam({url: listUrl }).trigger("reloadGrid");
                        }
                        return results;
                    }
                }
            );
            $(gridSelector).jqGrid ('navButtonAdd', gridPagerSelector,
                { caption: ""/*"Show"*/, buttonicon: "icon-search",
                  onClickButton: function() {
                       $(gridSelector)[0].triggerToolbar();
                  }
            });
        });
</r:script>
</body>
</html>